home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / macify13.shr / macify.hqx / Source / Macify Code / call_macify.c next >
Text File  |  1991-03-15  |  3KB  |  101 lines

  1. /* A little "pre-call" I added to allow file handling */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6. #define F_OK    1
  7. #define rindex strrchr
  8. #include <quickdraw.h>
  9. #include <StdFilePkg.h>
  10. #include <EventMgr.h>
  11. #include <FileMgr.h>
  12. #include <string.h>
  13. #include <pascal.h>
  14. #include <stdlib.h>
  15.  
  16. #define STRLEN        256            /* kludge */
  17.  
  18. void call_macify(stuff_to_do)
  19. int        stuff_to_do;
  20. {
  21.     int getfile(char *);        
  22.     short access(char *, short);        /* Pascal string */
  23.     FILE   *fp, *dfp, *fopen(); /* input file pointer and dest file
  24.                      * pointer */
  25.     char    Macfile[STRLEN];    /* file name gotten from user prompt */
  26.     char    Macoutfile[STRLEN];    /* file name for use as output */
  27.     FInfo    finfo;                /* for setting this file's finder info. */
  28.  
  29.     printf("\nWelcome to MACIFY.\n");
  30.  
  31.     if (getfile(Macfile) == FALSE)  {
  32.         printf("No selection made.\n");
  33.         return;    }
  34.     if (NULL == (fp = fopen(Macfile, "r"))) {
  35.         (void) printf("Error opening input file %s\n", Macfile);
  36.     }
  37.     /* Now we have a file to work with -- Macfile */
  38.     /* Use string catenation to come up with an output file */
  39.     strcpy(Macoutfile, Macfile);
  40.     strcat(Macoutfile, ".out");    /* Send output */
  41.     if (stuff_to_do == 1)    /* UNIX -> Mac? */
  42.         printf("UNIX File: %s ==> Mac File: %s\nConversion in progres...\n",
  43.             Macfile, Macoutfile);
  44.     else if (stuff_to_do == 2)    /* Mac -> UNIX? */
  45.         printf("Mac File: %s ==> UNIX File: %s\nConversion in progress...\n",
  46.             Macfile, Macoutfile);
  47.     macify(stuff_to_do, Macfile, Macoutfile);    /* actually do it */
  48. }
  49. int
  50. getfile (reply)
  51. char *reply;
  52. {
  53.     Point where;
  54.     SFReply frommac;
  55.     SFTypeList    whatTypes;
  56.     
  57.     whatTypes[0] = 'TEXT';
  58.     
  59.     where.h = 75; where.v = 50;
  60.     SFGetFile (where, (StringPtr)"\p", 0L, 1, &whatTypes, 0L, &frommac);
  61.     if (frommac.good) {
  62.       SetVol ((StringPtr)"\p", frommac.vRefNum);
  63.       PtoCstr((char *)frommac.fName);
  64.       strcpy (reply, (char *)frommac.fName);
  65.       return (TRUE);
  66.     }
  67.     else return (FALSE);
  68. }
  69.  
  70. /*
  71. ** access
  72. **
  73. ** takes two arguments, either of which can be null.
  74. ** returns 0 if the file exists, -1 if it doesn't exist.
  75. **
  76. */
  77. short 
  78. access(name, vRefNum)
  79. char *name;        /* Pascal string */
  80. short vRefNum;
  81. {
  82.     FInfo    info;
  83.     OSErr    err;
  84.     Str255    NotUsed;
  85.  
  86.     GetVol(NotUsed, &vRefNum);
  87.     
  88.     CtoPstr(name);
  89.     err = GetFInfo((StringPtr)name, vRefNum, &info);
  90.     PtoCstr(name);
  91.     if (err == fnfErr)
  92.         return -1;        /* file exists. */
  93.     else if (err == noErr)
  94.         return 0;        /* file doesn't exist */
  95.     else
  96.     {
  97.         printf("Error %d when trying to find file %s\n", err, name);
  98.         return 0;        /* file doesn't exist */
  99.     }
  100. }
  101.